package com.album.activity.pageView;

import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.Vector;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
 
import com.album.R;
import com.album.activity.MessageDialog;
import com.album.activity.adapter.DataAccountExpandablebaseadapter;
import com.album.activity.adapter.GridAdapter;
import com.album.activity.adapter.PhotoAdapter;
import com.album.activity.adapter.PhotopwdAdapter;
import com.album.activity.page.Page;
import com.album.activity.page.PageManager;
import com.album.bean.AlbumInfo;
import com.album.bean.ErrorInfo;
import com.album.bean.PicinfoList;
import com.album.bean.UserInfo;
import com.album.bean.loginInfo;
import com.album.http.HttpRequest;
import com.album.provider.ProviderUtil;
import com.album.task.DownImageTask;
import com.album.task.GetAlbumInfoTask;
import com.album.task.GetPicinfolistTask;
import com.album.task.ICallBack;
import com.album.task.Task;
import com.album.utils.CommonUtil;
import com.album.utils.MyLog; 
import com.google.gson.Gson;

public class MyPhotoView extends Page{

	private static String TAG = "MyPhotoView";
	 /** 
    * 文件夹下的图片列表 
    */  
	private List<Object> mImageList;
	/**
	 * 好友头像
	 */
   private List<Object> headImageList;
   private LinearLayout linearLayout; 
   private ListView casualListView;
	//private HorizontalScrollView scrollView;
   private ProgressBar progressHorizontal;
   private TextView progressText;
   private ProgressDialog dialog_1; 
   private ProgressDialog dialog_2;
   private  OperateHandler handler ;
   private Gson gson;
   private static final int ALBUM_INFO =1;
   private static final int ALBUM_FAIL =2; 
   private static final int PICINFOLIST_INFO =4;
   private static final int PICINFOLIST_INFO_FAIL =5;
   private static final int PICINFOLIST_RE_MYPTO_IMAGE =7;
   private static final int PICINFOLIST_DOWN_IMAGE_FAIL =8;
   private static final int TIME_OUT = 11;
   private static final int INTENT_ERROR = 12;
   private static final int HTTP_ERROR = 13;
   private TextView text_a;
   private TextView text_b;
   private TextView text_c;
   private TextView text_d;
   private ImageView userHead;
   private TextView text_user_name;
   
   /**adapter*/ 
   private Bitmap bm; 
   	
   private final int group_public=0;	//公开
   private final int group_pwd=1;		//私密
   private final int group_share=2;	//分享
   
    
   private PhotopwdAdapter adapter_pwds;
   
   private Context context;

	/***************************************/

	private RelativeLayout layout;
	
	private RelativeLayout layout1;
	private RelativeLayout layout2;
	private RelativeLayout layout3;
	
	private TextView tab1,tab2,tab3; 
	
	private ImageView first;
	private int current = 1; // 默认选中第一个，可以动态的改变此参数值
	private int selectedView =0;
	private ViewFlipper my_viewflipper;
	private com.album.activity.adapter.PhotoAdapter adapter;
	private GridView  gridView; 
	private List<SoftReference<Bitmap>> listBitmap;
	private boolean isAdd = false; // 是否添加过 top_select
	private int select_width; // top_select_width
	private int select_height; // top_select_height
	private int firstLeft; // 第一次添加后的左边距*****
	private int startLeft; // 起始左边距
	/************************************************/
	
	public MyPhotoView(PageManager manager) {
		super(manager);
	}

	@Override
	public View getView() {
		Log.i(TAG, "@Override getView");
		return linearLayout;
	}
	PhotoView photoView;
	@Override
	public void onCreate(Object extra) {
		super.onCreate(extra);
       Log.i(TAG, "onCreate");
		MyLog.info(CasualLookView.class, "onCreate()");
		context = manager.getContext();
		casualListView = new ListView(context);
		casualListView.setBackgroundColor(Color.BLACK);
		casualListView.setCacheColorHint(0x00000000);
		casualListView.setScrollbarFadingEnabled(false); 
		casualListView.setOnItemClickListener(new OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> parent, View view, 
					int position, long id) {
			}});
	    handler = new OperateHandler();
        mImageList = new ArrayList<Object>();
        headImageList = new ArrayList<Object>();
        headImageList.add(R.drawable.icon);
		LayoutInflater inflater = LayoutInflater.from(manager.getContext());
		linearLayout = (LinearLayout) inflater.inflate(
				R.layout.myphoto_image_list, null);
		userHead = (ImageView) linearLayout
				.findViewById(R.id.image_head);
		text_user_name = (TextView) linearLayout
		.findViewById(R.id.user_name);
		text_a = (TextView) linearLayout
		.findViewById(R.id.a);
		text_b = (TextView) linearLayout
		.findViewById(R.id.b);
		text_c = (TextView) linearLayout
		.findViewById(R.id.c);
		text_d = (TextView) linearLayout
		.findViewById(R.id.d);
		text_a.setBackgroundResource(R.drawable.rodio_1);//默认值
		//分类按钮点击事件
		setTextClicke();
		progressHorizontal = (ProgressBar) linearLayout
				.findViewById(R.id.progress_horizontal);
		progressText = (TextView)linearLayout
		        .findViewById(R.id.progress_text);
		progressText.setGravity(Gravity.CENTER); 
		initView();
		InputStream is = manager.getContext().getResources()
				.openRawResource(R.drawable.icon);
		Bitmap bm = BitmapFactory.decodeStream(is);
		bm = CommonUtil.getRoundedCornerBitmap(bm);
		userHead.setImageBitmap(bm);
		getAlbumInfo(null);
	}
	private void initView(){
		layout = (RelativeLayout)linearLayout.findViewById(R.id.root);
		
		layout1 = (RelativeLayout)linearLayout.findViewById(R.id.layout1);
		layout2 = (RelativeLayout)linearLayout.findViewById(R.id.layout2);
		layout3 = (RelativeLayout)linearLayout.findViewById(R.id.layout3);
		
		my_viewflipper = (ViewFlipper)linearLayout.findViewById(R.id.my_viewflipper);
		/********************************************************/
		gridView = (GridView)linearLayout.findViewById(R.id.gridView); 
		gridView.setGravity(Gravity.CENTER);// 位置居中 
		SoftReference<Bitmap> bitmap = adapter.drawableToBitmap(context.getResources().getDrawable(R.drawable.topbar_select));
		listBitmap = new ArrayList<SoftReference<Bitmap>>();
//		for(int i=0;i<10;i++){
//			listBitmap.add(bitmap);
//		} 
		adapter = new PhotoAdapter(context, listBitmap);
		/********************************************************/
		tab1 = (TextView)linearLayout.findViewById(R.id.tab1);
		tab1.setOnClickListener(onClickListener);
		tab2 = (TextView)linearLayout.findViewById(R.id.tab2);
		tab2.setOnClickListener(onClickListener);
		tab3 = (TextView)linearLayout.findViewById(R.id.tab3);
		tab3.setOnClickListener(onClickListener);
		
		RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		rl.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		first = new ImageView(context);
		first.setTag("first");
		first.setImageResource(R.drawable.topbar_select);
		
		// 默认选中项
		switch (current) {
		case 1:
			layout1.addView(first, rl); 
			current = R.id.tab1;
			break;
		case 2:
			layout2.addView(first, rl);
			current = R.id.tab2;
			break;
		case 3:
			layout3.addView(first, rl);
			current = R.id.tab3;
			break;
		default:
			break;
		}
		adapter = new PhotoAdapter(context, listBitmap);
		gridView.setAdapter(adapter);
		my_viewflipper.setDisplayedChild(selectedView);
	}
	// 添加一个view，移除一个view
	private void replace() {
		switch (current) {
		case R.id.tab1:
			changeTop(layout1);
			break;
		case R.id.tab2:
			changeTop(layout2);
			break;
		case R.id.tab3:
			changeTop(layout3);
			break;
		default:
			break;
		}
	}
	private void changeTop(RelativeLayout relativeLayout){
		ImageView old = (ImageView) relativeLayout.findViewWithTag("first");;
		select_width = old.getWidth();
		select_height = old.getHeight();
		
		RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(select_width, select_height);
		rl.leftMargin = old.getLeft() + ((RelativeLayout)old.getParent()).getLeft();
		rl.topMargin = old.getTop() + ((RelativeLayout)old.getParent()).getTop();
		
		// 获取起始位置
		firstLeft = old.getLeft() + ((RelativeLayout)old.getParent()).getLeft();
		
		ImageView iv = new ImageView(context);
		iv.setTag("move");
		iv.setImageResource(R.drawable.topbar_select);
		
		layout.addView(iv , rl);
		relativeLayout.removeView(old);
	}
	private OnClickListener onClickListener = new OnClickListener(){
		public void onClick(View v) {
			if(!isAdd){
				replace(); // 初次使用移除old 添加新的top_select为RelativeLayout所使用
				isAdd = true;
			}
			
			ImageView top_select = (ImageView) layout.findViewWithTag("move");
			int tabLeft;
			int endLeft = 0;
			
			boolean run = false;

			switch (v.getId()) {
			case R.id.tab1:
				if (current != R.id.tab1) {
					// 中心位置
					tabLeft = ((RelativeLayout) tab1.getParent()).getLeft() + tab1.getLeft() + tab1.getWidth() / 2;
					// 最终位置
					endLeft = tabLeft - select_width / 2;
					current = R.id.tab1;
					run = true;
					selectedView = 0;
				}
				break;
			case R.id.tab2:
				if (current != R.id.tab2) {
					tabLeft = ((RelativeLayout) tab2.getParent()).getLeft() + tab2.getLeft() + tab2.getWidth() / 2;
					endLeft = tabLeft - select_width / 2;
					current = R.id.tab2;
					run = true;
					selectedView = 1;
				}
				break;
			case R.id.tab3:
				if (current != R.id.tab3) {
					tabLeft = ((RelativeLayout) tab3.getParent()).getLeft() + tab3.getLeft() + tab3.getWidth() / 2;
					endLeft = tabLeft - select_width/2;
					current = R.id.tab3;
					run = true;
					selectedView = 2;
				}
				break;
			default:
				break;
			}
			
			if(run){
				TranslateAnimation animation = new TranslateAnimation(startLeft, endLeft - firstLeft, 0, 0);
				startLeft = endLeft - firstLeft; // 重新设定起始位置
				animation.setDuration(300);
				animation.setFillAfter(true);
				top_select.bringToFront();
				top_select.startAnimation(animation);
				my_viewflipper.setDisplayedChild(selectedView);
			}
			Bitmap bitmap = adapter.drawableBitmap(context.getResources().getDrawable(R.drawable.topbar_select));
			listBitmap.add(new SoftReference<Bitmap>(bitmap));
			adapter.setListDataSetChanged(bitmap);
//			my_viewflipper.removeAllViews();
			System.out.println("select:"+selectedView);
			
		}

	};
    private void setTextClicke(){
    	text_a.setOnClickListener(new View.OnClickListener(){
		    @Override
		     public void onClick(View v) {
		    	text_a.setBackgroundResource(R.drawable.rodio_1);
		    	text_b.setBackgroundResource(R.drawable.rodio_2);
		    	text_c.setBackgroundResource(R.drawable.rodio_2);
		    	text_d.setBackgroundResource(R.drawable.rodio_2);
		       }
		 });
    	text_b.setOnClickListener(new View.OnClickListener(){
		    @Override
		     public void onClick(View v) {
		    	text_a.setBackgroundResource(R.drawable.rodio_2);
		    	text_b.setBackgroundResource(R.drawable.rodio_1);
		    	text_c.setBackgroundResource(R.drawable.rodio_2);
		    	text_d.setBackgroundResource(R.drawable.rodio_2);
		       }
		 });
    	text_c.setOnClickListener(new View.OnClickListener(){
		    @Override
		     public void onClick(View v) {
		    	text_a.setBackgroundResource(R.drawable.rodio_2);
		    	text_b.setBackgroundResource(R.drawable.rodio_2);
		    	text_c.setBackgroundResource(R.drawable.rodio_1);
		    	text_d.setBackgroundResource(R.drawable.rodio_2);
		       }
		 });
    	text_d.setOnClickListener(new View.OnClickListener(){
		    @Override
		     public void onClick(View v) {
		    	text_a.setBackgroundResource(R.drawable.rodio_2);
		    	text_b.setBackgroundResource(R.drawable.rodio_2);
		    	text_c.setBackgroundResource(R.drawable.rodio_2);
		    	text_d.setBackgroundResource(R.drawable.rodio_1);
		       }
		 });
    }
    private DataAccountExpandablebaseadapter expandableAdapter;
//	private void initView(){
//
//		Map<Integer,String> groupData = new HashMap<Integer, String>();
//		groupData.put(0,"公开的照片");
//		groupData.put(1,"密码的照片");
//		groupData.put(2,"分享给好友的照片");
//		
//		List<HashMap<Integer, GridAdapter>> childData = new ArrayList<HashMap<Integer,GridAdapter>>();
//		
//		
//		
//    	list = new Vector<SoftReference<Bitmap>>(); 
////    	bm = CommonUtil.drawableToBitmap(context.getResources().getDrawable(R.drawable.icon));
//    	 
//         
//        
//        adapter_public = new GridAdapter(context,list);
//        adapter_pwd = new GridAdapter(context,list);
//        adapter_share = new GridAdapter(context,list);
//		
//		//二级列表 
//        HashMap<Integer,GridAdapter> child_public = new HashMap<Integer, GridAdapter>();
//        child_public.put(group_public,adapter_public);
//        childData.add(child_public);
//        
//        HashMap<Integer,GridAdapter> child_pwd = new HashMap<Integer, GridAdapter>();
//        child_pwd.put(group_pwd,adapter_pwd);
//        childData.add(child_pwd);
//        
//        HashMap<Integer,GridAdapter> child_share = new HashMap<Integer, GridAdapter>();
//		child_share.put(group_share,adapter_share);
//		childData.add(child_share);
//		 
//		 
//		expandableAdapter = new DataAccountExpandablebaseadapter(context,groupData, childData);
//
//		listAccount = (ExpandableListView)linearLayout.findViewById(R.id.listAccount);
//		listAccount.setAdapter(expandableAdapter);
//		// 去掉系统自带的按钮
//		listAccount.setGroupIndicator(null); 
//		// 去掉系统自带的分隔线
//		listAccount.setDivider(null);
//		listAccount.expandGroup(0);
//		
//		/** 
//         * 监听父节点打开的事件 
//         */ 
//		listAccount.setOnGroupExpandListener(new OnGroupExpandListener() {
//			
//			@Override
//			public void onGroupExpand(int groupPosition) {
//				// TODO Auto-generated method stub
//				Log.d("log", "groupPosition:"+groupPosition);
//				isExpanding=false;
//			}
//		});
//		
//		/** 
//         * 监听父节点关闭的事件 
//         */  
//		listAccount.setOnGroupCollapseListener(new OnGroupCollapseListener() {
//			
//			@Override
//			public void onGroupCollapse(int groupPosition) {
//				// TODO Auto-generated method stub
//				isExpanding=false;  
//			}
//		});
//	}
	private boolean isExpanding;
	
	public void clearImageList() {
		// 把已经存储的已选择图片的缩略图回收
		if (mImageList != null && mImageList.size() > 0) {
			for (int i = 0, l = mImageList.size(); i < l; i++) {
				InputStream is = manager
						.getContext()
						.getResources()
						.openRawResource(
								Integer.parseInt(mImageList.get(i).toString()));
				Bitmap bm = BitmapFactory.decodeStream(is);
				if (bm != null && !bm.isRecycled()) {
					bm.recycle();
				}
			}
			mImageList.clear();
		}
	}
	/**
	 * 获取相册空间信息
	 * @param username
	 * @return
	 */
	private String getAlbumInfo(String username){
		String rspString = null;
		if(gson == null)
		  gson = new Gson();
		username="18926128667@189.cn";
		Task task = new GetAlbumInfoTask(manager.getContext(),username, new ICallBack() {
			@Override
			public void CallBack(String imageUrl, Bitmap bm) {
			}
			@Override
			public void CallBack(String rspString) {
				if(HttpRequest.error.equals(rspString)){
					handler.sendEmptyMessage(INTENT_ERROR);
					return;
				}
				try {
					MyLog.info(getClass(), "jsonData:" + rspString);
					rspString = "[" + rspString + "]";
					JSONArray array = new JSONArray(rspString.toString());
					JSONObject obj = array.getJSONObject(0);
					if (obj.getBoolean("msg")) {
						JSONObject res = obj.getJSONObject("data");
						MyLog.info(getClass(), "jsonData:" + res.toString());
						AlbumInfo info = gson.fromJson(res.toString(), AlbumInfo.class);
						Message ms = new Message();
						ms.what = ALBUM_INFO;
						ms.obj = info;
						handler.sendMessage(ms);
					} else {
						AlbumInfo info=new AlbumInfo();
						info.setErrCode(obj.getString("errCode"));
						Message ms = new Message();
						ms.what = ALBUM_FAIL;
						ms.obj = info;
						handler.sendMessage(ms);
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
			@Override
			public void TimeOut() {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(TIME_OUT);
			}
			@Override
			public void HttpError(int errorCode) {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(TIME_OUT);
			}
		});
		dialog_1 = ProgressDialog.show(manager.getContext(), "", manager.getContext().getText(R.string.abluminfo_doing), true);
		dialog_1.setCancelable(false);
		task.doTask(task);
		return rspString;
	}

	/**
	 * 获取相册属性表
	 */
	private void getPicinfolist() {
		dialog_2 = ProgressDialog.show(manager.getContext(), "",
				manager.getContext().getText(R.string.imageinfo_doing),
				true);
		dialog_2.setCancelable(false);
		if (gson == null) {
			gson = new Gson();
		}
		String username = "18926128667@189.cn";
	    final int type = 4;
		final int public_=0;
		Task task = new GetPicinfolistTask(manager.getContext(),username, type,public_, null,
				new ICallBack() {
					@Override
					public void CallBack(String imageUrl, Bitmap bm) {
					}
					@Override
					public void CallBack(String rspString) {
						// TODO Auto-generated method stub
						MyLog.info(getClass(), "jsonData:" + rspString);
						if(HttpRequest.error.equals(rspString)){
							handler.sendEmptyMessage(INTENT_ERROR);
							return;
						}
						rspString = "[" + rspString + "]";
						JSONArray array;
						JSONArray array_data;
						List<String> imageList = new ArrayList<String>();
						try {
							array = new JSONArray(rspString.toString());
							JSONObject obj = array.getJSONObject(0);
							if (obj.getBoolean("msg")) {
								String res_data = obj.getString("data");
								MyLog.info(getClass(),
										"data:" + res_data.toString());
								array_data = new JSONArray(res_data.toString());
								for (int i = 0; i < array_data.length(); i++) {
									JSONObject obj_data = array_data.getJSONObject(i);
									MyLog.info(getClass(),"exif:" + obj_data.toString());
									PicinfoList info = new PicinfoList();
									info.setFileid(obj_data.getString("fileid"));
									info.setPassport(obj_data.getString("passport"));
									info.setPublic_(obj_data.getString("public"));
									info.setTypeid(obj_data.getString("typeid"));
									info.setUpload_time(obj_data.getString("upload_time"));
									info.setTitle(obj_data.getString("title"));
									info.setContent(obj_data.getString("content"));
									info.setViews(obj_data.getString("views"));
									info.setScore(obj_data.getString("score"));
									info.setBlock(obj_data.getString("block"));
									info.setArea(obj_data.getString("area"));
									info.setCoordinate(obj_data.getString("coordinate"));
									info.setPath_image(obj_data.getString("path_image"));
									info.setHash_code(obj_data.getString("hash_code"));
									MyLog.info(getClass(),
											"pricinfolist:" + info.getTypeid());
									ProviderUtil.insertOrUpdatePicinfoList(manager.getContext(), info);
									imageList.add(obj_data.getString("path_image"));
								}
								Message ms = new Message ();
								ms.what = PICINFOLIST_INFO;
								ms.arg1 = type;
								ms.arg2 = public_;
								ms.obj = imageList;
								handler.sendMessage(ms);
							} else {
								PicinfoList info = new PicinfoList();
								info.setErrCode(obj.getString("errCode"));
								Message ms = new Message ();
								ms.what = PICINFOLIST_INFO_FAIL;
								ms.obj = info;
								handler.sendMessage(ms);
							}
							
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
					@Override
					public void TimeOut() {
						//网络超时处理
						handler.sendEmptyMessage(TIME_OUT);
					}
					@Override
					public void HttpError(int errorCode) {
						// TODO Auto-generated method stub
						handler.sendEmptyMessage(TIME_OUT);
					}
				});
		task.doTask(task);
	}
	/**
	 * 下载图片
	 * @param filenameList
	 */
    private void downMyPtoImage(List<String> filenameList,final int type,final int public_){
    	String username = "18926128667@189.cn";
    	Task task = new DownImageTask(manager.getContext(), username, filenameList, new ICallBack() {
			@Override
			public void CallBack(String imageUrl, Bitmap bm) {
				//发handler 做刷新操作
				MyLog.info(getClass(), "image bm:"+bm);
				if(bm != null){	
				Message ms = new Message();
				ms.what = PICINFOLIST_RE_MYPTO_IMAGE;
				ms.arg1 = type;
				ms.arg2 = public_;
				ms.obj = bm;
				handler.sendMessage(ms);
				}else{
					Message ms = new Message();
					ms.what = PICINFOLIST_DOWN_IMAGE_FAIL;
				    handler.sendMessage(ms);
				}
				
			}
			
			@Override
			public void CallBack(String rspString) {
				
			}

			@Override
			public void TimeOut() {
				// TODO Auto-generated method stub
			}

			@Override
			public void HttpError(int errorCode) {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(TIME_OUT);
			}
		});
    	task.doTask(task);
    }
	class OperateHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			// 更新界面
			switch (msg.what) {
			case ALBUM_INFO:
				//获取头像跟用户名
				String  nick= ProviderUtil.getNick(manager.getContext());
				MyLog.info(getClass(), "nick:"+nick);
				text_user_name.setText(nick);
				//获取空间大小
				AlbumInfo info = (AlbumInfo) msg.obj;
				MyLog.debug(getClass(), info.getErrCode());
				MyLog.debug(getClass(), info.isMsg() + "");
				if (info != null) {
						MyLog.info(getClass(), "空间1：" + info.getAvailable());
						MyLog.info(getClass(), "空间2：" + info.getCapacity());
						int avaiable = Integer.parseInt(info.getAvailable());
						int capactity = Integer.parseInt(info.getCapacity());
						int noAvaiable = capactity - avaiable;
						double lo = ((double) noAvaiable / capactity) * 100;// 99.33
						MyLog.info(getClass(), "空间3：" + lo + "%");
						String str = String.valueOf(lo).substring(0,
								String.valueOf(lo).indexOf('.'));
						MyLog.info(getClass(), "空间信息：" + str + "%");
						progressHorizontal.setProgress(Integer.parseInt(str));
						progressText.setText(manager.getContext().getString(
								R.string.progresstext_1)
								+ str+"%"
								+ manager.getContext().getString(
										R.string.progresstext_2));
						//获取相册信息
						getPicinfolist();
				}
				if (dialog_1 != null && dialog_1.isShowing())
					dialog_1.dismiss();
				break;
			case ALBUM_FAIL: //获取空间信息失败
				AlbumInfo info_fail = (AlbumInfo) msg.obj;
				MessageDialog.showToast(manager.getContext(), false,
						ErrorInfo.errorMap.get(info_fail.getErrCode()));
				if (dialog_1 != null && dialog_1.isShowing())
					dialog_1.dismiss();
				break;
			case PICINFOLIST_INFO:
				List<String> imageList = (List<String>)msg.obj;
					//刷新分类属性按钮
					MyLog.info(getClass(), "type:"+msg.arg1);
					switch (msg.arg1) {
					case 1:
						text_a.setBackgroundResource(R.drawable.rodio_1);
						break;
					case 2:
						text_b.setBackgroundResource(R.drawable.rodio_1);
						text_a.setBackgroundResource(R.drawable.rodio_2);
						break;
					case 3:
						text_c.setBackgroundResource(R.drawable.rodio_1);
						text_a.setBackgroundResource(R.drawable.rodio_2);
						break;
					case 4:
						text_d.setBackgroundResource(R.drawable.rodio_1);
						text_a.setBackgroundResource(R.drawable.rodio_2);
						break;
					}
					if (dialog_2 != null && dialog_2.isShowing())
						dialog_2.dismiss();
					//下载我的相册图片信息
						if (imageList != null && imageList.size() > 0) {
							downMyPtoImage(imageList,msg.arg1,msg.arg2);
						}
				
				break;
			case PICINFOLIST_INFO_FAIL:// 获取相册信息失败
				PicinfoList picInfo_fail = (PicinfoList)msg.obj;
				MessageDialog.showToast(manager.getContext(), false,ErrorInfo.errorMap.get(picInfo_fail.getErrCode()));
				if (dialog_2 != null && dialog_2.isShowing())
					dialog_2.dismiss();
				break;
			case PICINFOLIST_RE_MYPTO_IMAGE:
				//刷新适配器获取图片信息
				Bitmap bm = (Bitmap)msg.obj;
				if(bm != null){
					int type = msg.arg1;
					int public_ = msg.arg2;
//					MyLog.debug(getClass(), "==============type:"+type+"\t"+"public_:"+public_);

					MyLog.debug(getClass(), "==============Height:"+bm.getHeight()+" Width:"+bm.getWidth()); 
//					listBitmap.add(new SoftReference<Bitmap>(bm));
					adapter.setListDataSetChanged(bm);
//					expandableAdapter.setNotifyDataSetChanged();
				}
				break;
			case PICINFOLIST_DOWN_IMAGE_FAIL://下载图片失败
				MessageDialog.showToast(manager.getContext(), false, manager.getContext().getString(R.string.imagedown_doing_fail));
				break;
			case TIME_OUT:
				if (dialog_1 != null && dialog_1.isShowing())
					dialog_1.dismiss();
				if (dialog_2 != null && dialog_2.isShowing())
					dialog_2.dismiss();
				MessageDialog.showToast(manager.getContext(), false, manager.getContext().getString(R.string.int_timeout));
				break;
			case INTENT_ERROR:
				if (dialog_1 != null && dialog_1.isShowing())
					dialog_1.dismiss();
				if (dialog_2 != null && dialog_2.isShowing())
					dialog_2.dismiss();
				MessageDialog.showToast(manager.getContext(), false, manager.getContext().getString(R.string.int_error));
				break;
			}
		}
	}
}
